package com.example.cashier.vm

import com.example.cashier.api.CashierApiService
import com.example.cashier.model.CashierResultData
import com.example.cashier.entity.CashierXaingEntityItem
import com.example.cashier.model.CashierRepository
import com.example.common.view.vm.BaseViewModel
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class CashierXiangViewModel @Inject constructor(private val apiService: CashierApiService): BaseViewModel<CashierRepository, CashierResultData<List<CashierXaingEntityItem>>>() {
    fun getCashierOrder(payerId:Int){
        mViewModelScope.launch (mDispatcher){
            try {
                val result=apiService.getCashierOrder(payerId)
                val res= CashierResultData(
                    state = result.state,
                    msg = result.msg,
                    data = result.data
                )
                mSuccessLiveData.postValue(res)
            }catch (e:Exception){
                mErrorLiveData.postValue("请求失败:${e.message}")
            }
        }
    }
}